#include "deinadd.h"
#include "ui_deinadd.h"

#include <QMessageBox>
#include <QDialog>
#include <QDebug>

deinAdd::deinAdd(QWidget *parent) :
    QWidget(parent),
    _ui(new Ui::deinAdd)
{
    _ui->setupUi(this);

    _market = new addmarket(this);

    connect(_ui->btn_market, SIGNAL(clicked()), this, SLOT(openMarket()));
    connect(_ui->btn_add, SIGNAL(clicked()), this, SLOT(openMarket()));
    connect(_ui->btn_hideAdd, SIGNAL(clicked()), this, SLOT(hideAddBTNByBTN()));

    _menuBar = new QMenuBar(this);
    _menuDatei = new QMenu("&Datei", this);

    _menuDatei->addAction(tr("Informationstab öffnen"), this, SLOT(openInfoTab()));
    _menuDatei->addSeparator();
    _menuDatei->addAction(tr("&Beenden"), this, SLOT(closeMe())),
    _menuBar->addMenu(_menuDatei);




    deinAddInitUI();

}

deinAdd::~deinAdd()
{
    delete _ui;
    delete _menuBar;
    delete _menuDatei;
    delete _menuTray;
    delete _systemTrayIcon,

    delete _market;
}
void deinAdd::deinAddInitUI()
{
    this->showMaximized();
    setupSystemTrayIcon();

    _ui->mdiInfo->showMaximized();
    _ui->Hauptlayout->insertWidget(0, _menuBar);
}

void deinAdd::openMarket()
{
    _market->show();
}

void deinAdd::openInfoTab()
{
    if(_ui->mdiInfo->isVisible()){
        qDebug() << "1";
        return;
    }
    else
    {
        _ui->mdiArea->addSubWindow(_ui->mdiInfo);
    }
}

void deinAdd::closeMe()
{
    if ( QMessageBox::question(this, tr("%1 Beenden?").arg( qApp->applicationName() ), tr("Wollen Sie <b>%1</b> wirklich beenden?").arg( qApp->applicationName()) , QMessageBox::Yes | QMessageBox::No , QMessageBox::Yes ) == QMessageBox::Yes ) {
        close();
    }
}

void deinAdd::setupSystemTrayIcon()
{
    _systemTrayIcon = new QSystemTrayIcon(QIcon(":/images/res/plus.png"), this);

    _menuTray = new QMenu(tr("Options"),this);
    _systemTrayIcon->setContextMenu(_menuTray);

    _systemTrayIcon->show();
    _systemTrayIcon->showMessage(qApp->applicationName(), tr("Willkommen!"), QSystemTrayIcon::Information);
}

void deinAdd::hideAddBTNByBTN()
{
    if(_ui->btn_add->isVisible())
    {
        _ui->btn_add->setVisible(false);
        _ui->btn_hideAdd->setText(tr("add-Button anzeigen"));
    }
    else
    {
        _ui->btn_add->setVisible(true);
        _ui->btn_hideAdd->setText(tr("add-Button verbergen"));
    }
}
